<template>
  <a-spin :spinning="confirmLoading">
    <!--查询区域-->
    <div class="jeecg-basic-table-form-container">
      <a-form @keyup.enter.native="searchQuery" :model="queryParam" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-row :gutter="24">
          <a-col :lg="6">
            <a-form-item label="签约商户">
              <j-search-select placeholder="请选择签约商户" v-model:value="queryParam.businessId" dict="caishui_business,name,id,type=1" />
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item label="服务公司">
              <j-search-select placeholder="请选择服务公司" v-model:value="queryParam.companyId" dict="caishui_service_company,name,id" />
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item label="退款状态">
              <j-dict-select-tag placeholder="请选择退款状态" v-model:value="queryParam.status" dictCode="refund_record_status"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :lg="6">
              <a-form-item label="业务参考号">
                <a-input placeholder="请输入业务参考号" v-model:value="queryParam.yurRef"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item label="收方账号">
                <a-input placeholder="请输入收方账号" v-model:value="queryParam.crtAccount"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item label="收方户名">
                <a-input placeholder="请输入收方户名" v-model:value="queryParam.crtName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="12">
              <a-form-item label="创建时间">
                <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" v-model:value="queryParam.createTime_begin" class="query-group-cust" />
                <span class="query-group-split-cust">~</span>
                <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" v-model:value="queryParam.createTime_end" class="query-group-cust" />
              </a-form-item>
            </a-col>
            <a-col :lg="12">
              <a-form-item label="提交时间">
                <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" v-model:value="queryParam.submitTime_begin" class="query-group-cust" />
                <span class="query-group-split-cust">~</span>
                <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" v-model:value="queryParam.submitTime_end" class="query-group-cust" />
              </a-form-item>
            </a-col>
            <a-col :lg="12">
              <a-form-item label="审核时间">
                 <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" v-model:value="queryParam.checkTime_begin" class="query-group-cust" />
                 <span class="query-group-split-cust">~</span>
                 <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" v-model:value="queryParam.checkTime_end" class="query-group-cust" />
              </a-form-item>
            </a-col>
            <a-col :lg="12">
              <a-form-item label="银行处理时间">
                 <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" v-model:value="queryParam.finishTime_begin" class="query-group-cust" />
                 <span class="query-group-split-cust">~</span>
                 <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" v-model:value="queryParam.finishTime_end" class="query-group-cust" />
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-col :lg="6">
                <a-button type="primary" preIcon="ant-design:search-outlined" @click="searchQuery">查询</a-button>
                <a-button type="primary" preIcon="ant-design:reload-outlined" @click="searchReset" style="margin-left: 8px">重置</a-button>
                <a @click="toggleSearchStatus = !toggleSearchStatus" style="margin-left: 8px">
                  {{ toggleSearchStatus ? '收起' : '展开' }}
                  <Icon :icon="toggleSearchStatus ? 'ant-design:up-outlined' : 'ant-design:down-outlined'" />
                </a>
              </a-col>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!--引用表格-->
    <BasicTable @register="registerTable">
      <!--插槽:table标题-->
      <template #tableTitle>
        <a-button :loading="exportIconLoading" type="primary" preIcon="ant-design:export-outlined" @click="handleExportXls"> 导出</a-button>
      </template>
      <!--付方信息插槽-->
      <template #paySlot="{record}">
        <span style="text-align: left;">
          <p>付方户名：<span >{{record.payName}}</span></p>
          <p>付方账号：<span >{{record.payAccount}}{{record.payDmanbr}}</span></p>
          <p>付方公司：<span >{{record.payDmanam}}</span></p>
        </span>
      </template>
      <!--收方信息插槽-->
      <template #artSlot="{record}">
        <span style="text-align: left;">
          <p>收方户名：<span >{{record.crtName}}</span></p>
          <p>收方账号：<span >{{record.crtAccount}}</span></p>
          <p>开户银行：<span >{{record.bankName}}</span></p>
          <p>开户支行：<span >{{record.bankBranch}}</span></p>
<!--          <p>开户地：<span >{{record.bankAddress}}</span></p>-->
        </span>
      </template>
      <!--退款金额插槽-->
      <template #moneySlot="{record}">
        <span style="text-align: left;">
          <p>退款金额：<span style="font-weight: bold;">{{parseFloat(record.money).toFixed(2)}}</span></p>
          <p>服务费：<span>{{parseFloat(record.serviceFee).toFixed(2)}}</span></p>
          <p>实际到账金额：<span style="font-weight: bold;">{{parseFloat(record.money-record.serviceFee).toFixed(2)}}</span></p>
        </span>
      </template>
      <!--银行处理结果插槽-->
      <template #reqSlot="{record}">
        <p v-if="!record.reqSts_dictText && !record.rtnFlg_dictText">-</p>
        <span style="text-align: left;">
          <p v-if="record.reqSts_dictText">请求状态：<span >{{record.reqSts_dictText}}</span></p>
          <p v-if="record.rtnFlg_dictText">业务处理结果：<span >{{record.rtnFlg_dictText}}</span></p>
          <p v-if="record.failReason">处理失败原因：<span >{{record.failReason}}</span></p>
        </span>
      </template>
      <!--退款状态插槽-->
      <template #statusSlot="{record}">
        <a-badge v-if="record.status==-1" color="grey" :text="record.status_dictText" />
        <a-badge v-if="record.status==0" color="cyan" :text="record.status_dictText" />
        <a-badge v-if="record.status==1" color="orange" :text="record.status_dictText" />
        <a-badge v-if="record.status==2" color="purple" :text="record.status_dictText" />
        <a-badge v-if="record.status==3" color="blue" :text="record.status_dictText" />
        <a-badge v-if="record.status==4" color="green" :text="record.status_dictText" />
        <a-badge v-if="record.status==5" color="red" :text="record.status_dictText" />
        <p v-if="record.status==2">驳回理由：<span >{{record.rejectReason}}</span></p>
      </template>
    </BasicTable>
  </a-spin>
</template>

<script lang="ts" name="caishuiRefundRecord-caishuiRefundRecord" setup>
  import { ref, reactive } from 'vue';
  import { BasicTable } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { columns } from './CaishuiRefundRecord.data';
  import { list, getExportUrl } from './CaishuiRefundRecord.api';
  import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue';
  import JSearchSelect from '/@/components/Form/src/jeecg/components/JSearchSelect.vue';
  import { useMessage } from "/@/hooks/web/useMessage";
  import { useUserStore } from "/@/store/modules/user";

  const userStore = useUserStore();
  const queryParam = ref<any>({});
  const toggleSearchStatus = ref<boolean>(false);
  const exportIconLoading = ref<boolean>(false);
  const confirmLoading = ref<boolean>(false);
  const { createMessage } = useMessage();

  //注册table数据
  const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
    tableProps: {
      title: '退款记录',
      api: list,
      columns,
      canResize:false,
      useSearchForm: false,
      striped: true,
      showIndexColumn: true,
      ellipsis: false,
      showActionColumn: false,
      actionColumn: {
        width: 150,
        fixed: 'right',
      },
      beforeFetch: (params) => {
        return Object.assign(params, queryParam.value);
      },
    },
    exportConfig: {
      name: "退款记录",
      url: getExportUrl,
      success: exportXlsSuccess
    },
  });
  const [registerTable, { reload, collapseAll, updateTableDataRecord, findTableDataRecord, getDataSource }, { rowSelection, selectedRowKeys }] = tableContext;
  const labelCol = reactive({
    xs: { span: 24 },
    sm: { span: 6 },
  });
  const wrapperCol = reactive({
    xs: { span: 24 },
    sm: { span: 16 },
  });

  /**
   * 成功回调
   */
  function handleSuccess() {
    (selectedRowKeys.value = []) && reload();
  }

  /**
   * 查询
   */
  function searchQuery() {
    reload();
  }
  
  /**
   * 重置
   */
  function searchReset() {
    queryParam.value = {};
    selectedRowKeys.value = [];
    //刷新数据
    reload();
  }

  /**
   * 导出
   */
  function handleExportXls() {
    exportIconLoading.value = true;
    onExportXls();
  }

  /**
   * 导出成功回调
   */
  function exportXlsSuccess(data) {
    exportIconLoading.value = false;
  }

</script>

<style lang="less" scoped>
  .jeecg-basic-table-form-container {
    .table-page-search-submitButtons {
      display: block;
      margin-bottom: 24px;
      white-space: nowrap;
    }
    .query-group-cust{
      width: calc(50% - 15px);
      min-width: 100px !important;
    }
    .query-group-split-cust{
      width: 30px;
      display: inline-block;
      text-align: center
    }
  }
</style>
